//
//  MeiSView.m
//  MyProject
//
//  Created by dllo on 15/11/20.
//  Copyright © 2015年 蓝鸥0825. All rights reserved.
//

#import "MeiSView.h"
#import "MeiSTableCell.h"
#import "UIImageView+WebCache.h"
#import "MeiSsecController.h"

@implementation MeiSView 

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}


- (void)create{
    
    self.tabel = [[UITableView alloc] init];
    [self addSubview:self.tabel];
    self.tabel.delegate = self;
    self.tabel.dataSource = self;
    self.tabel.bounces = NO;
    self.tabel.showsVerticalScrollIndicator = NO;
}






- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *reuse = @"reuse";
    self.cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!self.cell) {
        self.cell = [[MeiSTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    self.cell.label.text = self.array[indexPath.row][@"name"];
//    cell.label.layer.borderWidth = 1;
    
    self.cell.scroll.delegate = self;
//    self.cell.scroll.layer.borderWidth = 1;
    self.cell.scroll.pagingEnabled = YES;
    self.arr = self.array[indexPath.row][@"dishes"][@"dishes"];
    self.cell.scroll.contentSize = CGSizeMake(self.cell.scroll.frame.size.width * self.arr.count, 0);
    self.cell.scroll.bounces = NO;
    
    self.cell.view.image = [UIImage imageNamed:@"placeholder.png"];

    for (int i = 0; i < self.arr.count; i++) {
        
        self.image = [[UIImageView alloc] initWithFrame:CGRectMake(self.cell.scroll.frame.size.width * i, 0, self.cell.scroll.frame.size.width, self.cell.scroll.frame.size.height)];
//        image.layer.borderWidth = 1;
        self.image.userInteractionEnabled = YES;
        
        
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        //      把手势加到指定的视图上
        [self.image addGestureRecognizer:tap];
        [tap release];
        //      点几下才能触发的方法
        tap.numberOfTapsRequired = 1;

        
        
        [self.image sd_setImageWithURL:self.arr[i][@"thumbnail_280"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
        [self.cell.scroll addSubview:self.image];
    }
    
  return self.cell;
}


//      点击之后触发的方法
- (void)tapAction: (UITapGestureRecognizer *)tap {
    
    NSLog(@"你摸这啊");
    UIImageView *imageView = (UIImageView *)tap.view;
    
    MeiSsecController *secVC = [[MeiSsecController alloc] init];
    [self.VC.navigationController pushViewController:secVC animated:YES];
    secVC.image = imageView.image;
}


@end
